<template>
  <div class="searchResult-container">
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <van-cell @click="$router.push('/article/'+item.art_id)" v-for="item in resultsList" :key="item.id" :title="item.title"/>
    </van-list>
  </div>
</template>
           
<script>
import { getSearchResult_api } from '@/api/search.js'
export default {
  props: ['searchVal'],
   data() {
    return {
      list: [],
      loading: false,
      finished: false,
      resultsList:[],  // 搜索结果
      page:1
    };
  },
  methods: {
    async onLoad() {
      //  h获取搜索结果数据
      const  {data:res}=await getSearchResult_api({
        page:this.page,
        per_page:20,
        q:this.searchVal
      })
      console.log(res,4444);
      this.resultsList=[...this.resultsList,...res.data.results]
     //this.resultsList=res.data.results

      this.loading=false

      //  判断是否获取的数据有 
      if(res.data.results.length){
        this.page++
      }else{
        this.finished=true
      }
    },
  }
}
</script>
<style scoped>
</style>